﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Silverlight.Testing;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PlottingBasics.Functions;
using System.Text;

namespace t_PlottingBasics
{
    [TestClass]
    public class t_Poison
    {
        [TestMethod]
        public void TestbasicReturns08()
        {
            var f = Poisson.Pois(0.8);
            AreEqual(0.449328964, f(0), 0.0001, "0 value is not right");
            AreEqual(0.359463171, f(1), 0.0001, "1 value is not right");
            AreEqual(0.143785269, f(2), 0.0001, "2 value is not right");
        }

        [TestMethod]
        public void TestBaiscReturn3()
        {
            var f = Poisson.Pois(3.0);
            AreEqual(0.224041808, f(3), 0.001, "value for 3 isn't right");
            AreEqual(0.100818813, f(5), 0.001, "value for 5 isn't right");
            AreEqual(0.008101512, f(8), 0.001, "value for 8 isn't right");
        }

        /// <summary>
        /// Do a simple test and throw if no good
        /// </summary>
        /// <param name="p"></param>
        /// <param name="p_2"></param>
        /// <param name="p_3"></param>
        /// <param name="p_4"></param>
        private void AreEqual(double expected, double actual, double tolernace, string message)
        {
            double delta = Math.Abs(actual - expected);
            if (delta > tolernace)
            {
                StringBuilder bld = new StringBuilder();
                bld.AppendFormat("Expected value ({0}) not withing tolerance ({1}) of actual value ({2}) - {3}",
                    expected, tolernace, actual, message);
                throw new AssertFailedException(bld.ToString());
            }
        }
    }
}